package com.example.home.bus.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.home.R;

public class MakeNext2 extends AppCompatActivity {


    private TextView start;
    private TextView end;
    private EditText path;
    private EditText iphone;
    private EditText upPoint;
    private EditText offPlace;
    private Button btnLast;
    private Button btnNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_make_next2);
        // 获取从上一步页面传递过来的数据
        Intent intent = getIntent();
        String startValue = intent.getStringExtra("start");
        String endValue = intent.getStringExtra("end");
        String priceValue = intent.getStringExtra("price");
        String pathValue = intent.getStringExtra("path1");
        String selectedDateValue = intent.getStringExtra("selectedDate");

        intiView();

        start.setText(String.valueOf(startValue));
        end.setText(String.valueOf(endValue));


        btnNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = path.getText().toString();
                String iphNum = iphone.getText().toString();
                String uponint1 = upPoint.getText().toString();
                String offplace1 = offPlace.getText().toString();

                Intent intent = new Intent(MakeNext2.this,MakeNext3.class);
                intent.putExtra("start", startValue);
                intent.putExtra("end", endValue);
                intent.putExtra("price", priceValue);
                intent.putExtra("path1", pathValue);
                intent.putExtra("name", name);
                intent.putExtra("iphNum", iphNum);
                intent.putExtra("uponint1", uponint1);
                intent.putExtra("offplace1", offplace1);
                Log.e("xhf",selectedDateValue);
                intent.putExtra("selectedDateValue", selectedDateValue);
                startActivity(intent);
            }
        });

        path.addTextChangedListener(watcher);
        iphone.addTextChangedListener(watcher);
        upPoint.addTextChangedListener(watcher);
        offPlace.addTextChangedListener(watcher);

    }

    private TextWatcher watcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            // Check if any of the EditText fields has content
            boolean hasContent = !TextUtils.isEmpty(path.getText())
                    || !TextUtils.isEmpty(iphone.getText())
                    || !TextUtils.isEmpty(upPoint.getText())
                    || !TextUtils.isEmpty(offPlace.getText());

            // Update the visibility of the btnNext button
            btnNext.setVisibility(hasContent ? View.VISIBLE : View.INVISIBLE);
        }
    };



    private void intiView() {
        start = findViewById(R.id.start);
        end = findViewById(R.id.end);
        path = findViewById(R.id.path);
        iphone = findViewById(R.id.iphone);
        upPoint = findViewById(R.id.up_point);
        offPlace = findViewById(R.id.off_place);

        btnLast = findViewById(R.id.btn_last);
        btnLast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MakeNext2.this.finish();
            }
        });

        btnNext = findViewById(R.id.btn_next);

    }
}